﻿using System.Collections;
using DVDTek_Data_Object.DataObject;

namespace DVDTek_Data_Object.Collection
{
    public class DirectorCollection
    {
        #region Members
        private ArrayList directors = new ArrayList();

        public int Count
        {
            get { return this.directors.Count; }
        }

        public DirectorDataObject this[int i]
        {
            get
            {
                return (DirectorDataObject)this.directors[i];
            }
            set
            {
                if (value == null)
                    RemoveAt(i);
                else
                    this.directors[i] = value;
            }
        }
        #endregion

        #region Constructors
        public DirectorCollection()
        {
        }
        #endregion

        #region Functions
        public void Add(DirectorDataObject item)
        {
            this.directors.Add(item);
        }

        public void Clear()
        {
            this.directors.Clear();
        }

        public bool Contains(DirectorDataObject item)
        {
            return this.directors.Contains(item);
        }

        #region IndexOf
        public int IndexOf(DirectorDataObject item)
        {
            return this.directors.IndexOf(item);
        }

        public int IndexOf(DirectorDataObject item, int startIndex)
        {
            return this.directors.IndexOf(item, startIndex);
        }

        public int IndexOf(DirectorDataObject item, int startIndex, int count)
        {
            return this.directors.IndexOf(item, startIndex, count);
        }
        #endregion

        public void Insert(int index, DirectorDataObject value)
        {
            this.directors.Insert(index, value);
        }

        #region LastIndexOf
        public int LastIndexOf(DirectorDataObject value)
        {
            return this.directors.LastIndexOf(value);
        }

        public int LastIndexOf(DirectorDataObject value, int startIndex)
        {
            return this.directors.LastIndexOf(value, startIndex);
        }

        public int LastIndexOf(DirectorDataObject value, int startIndex, int count)
        {
            return this.directors.LastIndexOf(value, startIndex, count);
        }
        #endregion

        #region Remove
        public bool Remove(DirectorDataObject item)
        {
            int index = this.directors.IndexOf(item);
            if (index >= 0)
            {
                this.directors.RemoveAt(index);
                return true;
            }
            else
                return false;
        }

        public void RemoveAt(int i)
        {
            this.directors.RemoveAt(i);
        }

        public void RemoveRange(int index, int count)
        {
            this.directors.RemoveRange(index, count);
        }
        #endregion

        #region Reverse
        public void Reverse()
        {
            this.directors.Reverse();
        }

        public void Reverse(int index, int count)
        {
            this.directors.Reverse(index, count);
        }
        #endregion

        #region Sort
        public void SortByName(bool ascending)
        {
            for (int i = 0; i < Count - 1; i++)
            {
                int index = i;
                for (int j = i + 1; j < Count; j++)
                {
                    if (string.Compare(this[index].Name, this[j].Name) > 0)
                        index = j;
                }
                if (index != i)
                {
                    DirectorDataObject actor = this[index];
                    this[index] = this[i];
                    this[i] = actor;
                }
            }

            if (!ascending)
                Reverse();
        }
        #endregion

        public DirectorDataObject[] ToArray()
        {
            DirectorDataObject[] array = new DirectorDataObject[Count];
            for (int i = 0; i < Count; i++)
                array[i] = this[i];
            return array;
        }

        public void TrimToSize()
        {
            this.directors.TrimToSize();
        }
        #endregion
    }
}
